﻿using ConfExpert.Forms.Base;
using ConfExpert.Forms.Depo;
using ConfExpert.Properties;

using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.SatinAlma
{
    public partial class SRGomlekleri : XForm
    {
        public SRGomlekleri()
        {
            InitializeComponent();
        }

        private void SRGomlekleri_Load(object sender, EventArgs e)
        {
            gvSRGomlek.Init("GetSRGomlekler");
            gvSRGomlek.AddSummary();
            gvSRGomlek.AddColumn("Sec", typeof(bool));
            gvSRGomlek.YanYanaGetir("Sec:DosyaNo");

            gvSRGomlek.SetCaptions(
                "ProductId:Art1",
                "Renk:Col",
                "Konstruksiyon:Const",
                "KompozisyonId:Comp",
                "FinishId:F.Finish",
                "EnGrubu:F.Width",
                "Product1Id:Art2",
                "GarniArt:Col2",
                "Konstruksiyon1:Const",
                "Kompozisyon1Id:Comp",
                "Finish1Id:F.Finish",
                "EnGrubu1:F.Width",
                "Product2Id:Art3",
                "GarniArt2:Col3",
                "Konstruksiyon2:Const",
                "Kompozisyon2Id:Comp",
                "Finish2Id:F.Finish",
                "EnGrubu2:F.Width",
                "Product3Id:Art4",
                "GarniArt3:Col4",
                "Konstruksiyon3:Const",
                "Kompozisyon3Id:Comp",
                "Finish3Id:F.Finish",
                "EnGrubu3:F.Width",
                "Product4Id:Art5",
                "GarniArt4:Col5",
                "Konstruksiyon4:Const",
                "Kompozisyon4Id:Comp",
                "Finish4Id:F.Finish",
                "EnGrubu4:F.Width",

                "Sezon:Season",
                //"Model:ModelNo",

                "TYaka:Yaka T",
                "TManset:Manşet T",
                "TKusak:Kuşak T"
                );

            DevExpress.XtraEditors.Repository.RepositoryItem ri = RI(Rp.Tela);
            foreach (string colName in "TYaka,TKusak,TManset".Split(','))
                gvSRGomlek.Columns[colName].ColumnEdit = ri;

            gvSRGomlek.BestFitColumns();

            gvSRGomlek.Columns["Artikel"].Width =
                gvSRGomlek.Columns["GarniArt"].Width =
                gvSRGomlek.Columns["GarniArt2"].Width =
                gvSRGomlek.Columns["GarniArt3"].Width =
                gvSRGomlek.Columns["GarniArt4"].Width =
                100;

            GridManager gmArt = GridManager.GetManager(gvSRGomlek);
            gmArt.GridMenu.AddMenu("Seç", SatirSec, Resources.Plus_16x16);
            gmArt.GridMenu.AddMenu("Bırak", SatirBirak, Resources.Minus_16x16);
            gmArt.GridMenu.AddMenu("Showroom etiketi çıkar", PrintSREtiket);

            btnExceleAktar.ItemClick += btnExceleAktar_ItemClick;
        }

        private void PrintSREtiket(object sender, EventArgs e)
        {
            gvSRGomlek.EndEditing();

            DataRow[] drGomlek = gvSRGomlek.DataTable().Select("Sec=1");

            if (drGomlek.Length == 0)
            {
                ShowErrorMessage("Lütfen etiket almak istediğiniz satırları seçin");
                return;
            }
            DataTable dtEtiket = drGomlek.CopyToDataTable();
            using (ArsivEtiketi ne = new ArsivEtiketi(dtEtiket))
                ne.ShowDialog();
        }

        void btnExceleAktar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvSRGomlek.EndEditing();
            string eskifiltre = gvSRGomlek.ActiveFilterString;
            gvSRGomlek.ActiveFilterString = "[Sec] = True";

            gvSRGomlek.ExportToExcel();

            gvSRGomlek.ActiveFilterString = eskifiltre;
            gvSRGomlek.BestFitColumns();
        }

        private void bbiGuncelle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvSRGomlek.RefreshDataSource("GetSRGomlekler");
        }

        private void SatirBirak(object sender, EventArgs e)
        {
            foreach (int handle in gvSRGomlek.GetSelectedRows())
                gvSRGomlek.SetRowCellValue(handle, "Sec", false);
        }

        private void SatirSec(object sender, EventArgs e)
        {
            foreach (int handle in gvSRGomlek.GetSelectedRows())
                gvSRGomlek.SetRowCellValue(handle, "Sec", true);
        }
    }
}
